﻿using System;

namespace Aeon.Framework
{
  
/// <summary>
/// Value object for spatial position representation and transformation.
/// [TODO] This really should be a class.
/// 
/// </summary>
public struct Position
    {
    // --- Shared:
    
    private static Position origin = new Position(0,0,0);           // Convenient origin.
    public static Position Origin { get { return(origin); } }       // Accessor.
    
    // --- Fields/Accessors:
    
    private Single x;   public Single xPos { get { return(x); } }   // Component X.
    private Single y;   public Single yPos { get { return(y); } }   // Component Y.
    private Single z;   public Single zPos { get { return(z); } }   // Component Z.
    
    // --- Constructor:

    public Position(Single px, Single py) : this(px,py,0) { }
    public Position(Single px, Single py, Single pz) { x = px; y = py; z = pz;  }
    
    // --- Public Methods:

    public void Change(Position change)
        {
        x = change.xPos;
        y = change.yPos;
        z = change.zPos;
        }

    public void Transform(IVector vector)
        {
        x += vector.X;
        y += vector.Y;
        z += vector.Z;
        }
        
    public IVector Distance(Position pos)
        {
        // Lazy distance:
        
        return(new VectorC(pos.xPos-x,pos.yPos-y,pos.zPos-z));
        }

    public int Distance2(Position pos)
        {
        // Linear approximation:
        int a = (int) (Math.Pow((z-pos.z),2)+Math.Pow((z-pos.z),2)+Math.Pow((z-pos.z),2)); 

        return(a);
        }

    public float Distance3(Position pos)
        {
        // Real distance:
        float d = (float) (Math.Sqrt( Math.Pow(x-pos.x,2) + Math.Pow(y-pos.y,2) + Math.Pow(z-pos.z,2)) );

        return(d);
        }
        
    }

    
}
